Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tapable

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tapable

Just a little module for plugins.

  • 0.1.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
36M
increased by5.73%
Maintainers
1
Weekly downloads
 
Created

What is tapable?

The tapable package provides a collection of classes that can be used to add hooks into a plugin system. These hooks can be used to intercept and modify the behavior of certain functions or events, allowing for a highly customizable and extensible architecture. It is commonly used in webpack's plugin system but can be used in any JavaScript project to add similar plugin capabilities.

What are tapable's main functionalities?

SyncHook

SyncHook allows for synchronous execution of multiple functions. It is useful when you need to ensure that hooks are executed in the order they were added.

const { SyncHook } = require('tapable');

const hook = new SyncHook(['arg1', 'arg2']);

hook.tap('MyPlugin', (arg1, arg2) => {
  console.log(`Values received: ${arg1}, ${arg2}`);
});

hook.call('Hello', 'World');

AsyncParallelHook

AsyncParallelHook allows for asynchronous execution of hooks in parallel. It is useful when you have multiple asynchronous tasks that can run at the same time without waiting for each other.

const { AsyncParallelHook } = require('tapable');

const asyncHook = new AsyncParallelHook(['arg1']);

asyncHook.tapPromise('AsyncPlugin', (arg1) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      console.log(`Async value: ${arg1}`);
      resolve();
    }, 1000);
  });
});

asyncHook.promise('Hello').then(() => {
  console.log('All async plugins have finished.');
});

AsyncSeriesHook

AsyncSeriesHook allows for asynchronous execution of hooks one after another. It is useful when tasks need to be done in a specific sequence, with each task starting only after the previous one has completed.

const { AsyncSeriesHook } = require('tapable');

const asyncSeriesHook = new AsyncSeriesHook(['arg1']);

asyncSeriesHook.tapPromise('AsyncSeriesPlugin', (arg1) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      console.log(`Async series value: ${arg1}`);
      resolve();
    }, 1000);
  });
});

asyncSeriesHook.promise('World').then(() => {
  console.log('All async series plugins have finished.');
});

Other packages similar to tapable

FAQs

Package last updated on 24 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc